// Copyright (c) 2011, Grant China
// All rights reserved.

package org.gwtlcars.ui;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class LcarsPanelTopLeft extends LcarsPanel {

    private static LcarsPanelUiBinder uiBinder = GWT
            .create(LcarsPanelUiBinder.class);

    interface LcarsPanelUiBinder extends UiBinder<Widget, LcarsPanelTopLeft> {
    }

    @UiField
    HorizontalPanel hpanel;

    @UiField
    Label hpanel_spacer;

    @UiField
    FlowPanel vpanel;

    @UiField
    VerticalPanel vpanel_right_elbo;
    @UiField
    Label lbl_top_left;
    @UiField
    Label lbl_top_right;
    @UiField
    Label lbl_bottom_left;

    public LcarsPanelTopLeft() {
        initWidget(uiBinder.createAndBindUi(this));

        hpanel_idx = 2;
        vpanel_idx = 1;

        setColor(color);
    }

    @Override
    public void setColor(String lcars_color) {
        vpanel.removeStyleName(color);
        hpanel_spacer.removeStyleName(color);
        vpanel_right_elbo.removeStyleName(color);
        lbl_top_left.removeStyleName(color);
        lbl_top_right.removeStyleName(color);
        lbl_bottom_left.removeStyleName(color);

        color = lcars_color;

        vpanel.addStyleName(color);
        hpanel_spacer.addStyleName(color);
        vpanel_right_elbo.addStyleName(color);
        lbl_top_left.addStyleName(color);
        lbl_top_right.addStyleName(color);
        lbl_bottom_left.addStyleName(color);
    }

    public LcarsPanelButton addHorizontalButton(String html) {
        LcarsPanelButton button = new LcarsPanelButton(html);
        button.setColor(color);

        button.setHorizontal();
        if (hpanel_idx == 2)
            button.setFirstHorizontal();

        button.setWidth("100px");

        hpanel.insert(button, hpanel_idx);
        ++hpanel_idx;

        return button;
    }

    public LcarsPanelButton addVerticalButton(String html) {
        LcarsPanelButton button = new LcarsPanelButton(html);
        button.setColor(color);

        button.setVertical();
        if (vpanel_idx == 1)
            button.setFirstVertical();

        vpanel.add(button);
        ++vpanel_idx;

        return button;
    }
}
